$(document).ready(function(){
	$("#modifyUser").val(username);
	
	var src = tl_config.his_url;
	var i = src.indexOf('?');
	if(i!=-1){
		var id = src.substring(i+4);
        $.ajax({
        	url:server_url+'/rest/dictType/selectDictTypeById.do?ran='+Math.random()+ '&token=' + token,
        	type:'get',
        	data:{id:id},
        	success:function(data){
        		if(data.retCode=='1003'){
					localStorage.clear();
					window.location.href="login.do";
					return;
				}
        		if(data.retCode==='0000'){
        			$("#id").val(data.data.id);
        			$("#typeName").val(data.data.typeName);        			
        			$("#typeDesc").val(data.data.typeDesc);
        		}
        	}
        });
	}	
	

	//表单验证
	var validate = $("#fromEditDictType").validate({		   
			rules:{					
				typeName:{
					  required:true,
				      remote: { 
		                   url: server_url+'/rest/dictType/checkTypeNameEdit.do?timestamp='+Math.random()+ '&token=' + token,
		                   type: "post",
		                   dataType: "json", 
		                   data: {	
		                	         id: function() { return $("#id").val();},
		                	         typeName: function() { return $("#typeName").val();}
		                         } 
		               },
		               stringMaxLength:30
				}		   
			},
			messages:{				
				typeName:{
				      required:"该值不能为空！",
	                  remote:"字典分类名已存在，请重新输入!",
	                  stringMaxLength:"最多能输入30个字符！"
	                 }
			},
			submitHandler:function(){
				sub();
			},
			errorPlacement: function(error, element) {
				if ( element.is(":radio") )
					error.appendTo ( element.parent() );
				else if ( element.is(":checkbox") )
					error.appendTo ( element.parent() );
				else if ( element.is("input[name=captcha]") )
					error.appendTo ( element.parent() );
				else
					error.insertAfter(element);
			},
			validClass : 'rightValidate',
		    success: function(label) {
			   label.html("&nbsp;").text(" ") ;
		    }
	 });		

});


//提交
function sub(){	
	if($("#fromEditDictType").valid()){
		$.ajax({
			url:server_url+'/rest/dictType/dictTypeEdit.do?ran='+Math.random()+ '&token=' + token,
			type:'post',
			data:$("#fromEditDictType").serialize(),
			success:function(data){
				easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose: 2000});
				back();
			}
		});
	}
}


function back(){
//	$('.g_rightMidden').html("");
//	$(".g_rightMidden").load("getDictTypeInfoPage.do?ran="+Math.random());
	
	var url="getDictTypeInfoPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$("#fromEditDictType").submit();
}
